<?php
########################################################
# DMS Donations Management System v1.0                 #
# created by:  Isaac Sabas                             #
#			   Nikko Reyes							   #
#			   Miko Tiamwatt						   #
#                                                      #
# De La Salle Philippines                              #
# All Rights Reserved DLSP Copyright 2009              #
########################################################

define('START', true);	

session_start();	

# session security #
	if(!isset($_SESSION['initialized'])){
		session_regenerate_id();
		$_SESSION['initialized'] = true;		
		$_SESSION['SID'] = session_id();
		$_SESSION['logged'] = false;
		$_SESSION['loginError'] = '';
	}
		
# set error checking levels #			
	# enable these lines when site is to be deployed #	
	ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 'On');
    //ini_set('log_errors', 'On');
    //ini_set('error_log', '/usr/local/apache/logs/error_log');
	
# include some needed files #	
	include('lib/PEAR/PEAR/Sigma.php');	
	include('lib/XAJAX/xajax_core/xajax.inc.php');
	
# instantiate predifined classes #
	$template = new HTML_Template_Sigma('templates', 'templates-cache');												
	$xajax = new xajax();				

# register all functions to be handled by XAJAX framework #
	/*function echo_ajaxtest($text) {
		$objResponse = new xajaxResponse();
					
		$objResponse->addAssign("_ajaxtest.response","innerHTML", $text);				
		
		return $objResponse;
	}

	$xajax->registerFunction("echo_ajaxtest");
	*/

# page variables #
	$page_title = 'De La Salle University | Donations Management System ';
	$css = 'css/index.css';
	//$xajax_directives = $xajax->getJavascriptConfig() . $xajax->getJavascriptInclude('lib/XAJAX/');										
	
	# height of the dashboard #
		$contentHeight = 670;
		$clientToCallListHeight = $contentHeight - 50;
	
	# user credentials #
		$loginMessage = '';
		$username = '';
	
# login logout section #	
	if ($_SESSION['logged']) {
		# dashboard page template variables processor section (initialize all dashboard needed template variables) #
			# load dashboard template to buffer #
				$template->loadTemplateFile('dashboard.html');
			# initialize dashboard variables #
				$username = $_SESSION['agentUsername'];
		# privelage filter section #	
		if ($_SESSION['agentPermissions'] == 3) {
			//echo "3";
		}
		elseif ($_SESSION['agentPermissions'] == 2) {
			//echo "2";
		}
		elseif ($_SESSION['agentPermissions'] == 1) {
			$template->touchBlock('telemarketersTab');
			$template->touchBlock('telemarketersContentTab');
			$template->touchBlock('settingsTab');
			$template->touchBlock('settingsContentTab');
		}
		else {
			//echo "0";
		}
	}
	else {
		# load login template to buffer #
			$template->loadTemplateFile('login.html');
			if($_SESSION['loginError'] != '') {
				$loginMessage = $_SESSION['loginError'];
			}
			$_SESSION['loginError'] = '';
	}
# set template variables #
	$template->setVariable('PAGE_TITLE', $page_title);	
	$template->setVariable('STYLE', $css);
	
	$template->setVariable('loginMessage', $loginMessage);

	$template->setVariable('contentHeight', $contentHeight . 'px');
	$template->setVariable('clientToCallListHeight', $clientToCallListHeight . 'px');
	//$template->setVariable('XAJAX_INIT', $xajax_directives);
	
	$template->setVariable('agentUsername', $username);
		
# render the index template #
	//$xajax->processRequests();	
	$template->show();		
?>
